package cn.cjlmonster.demo02.api.callback;

import cn.cjlmonster.demo02.api.BaseResult;
import cn.cjlmonster.demo02.utils.JTools;
import io.reactivex.disposables.Disposable;

/**
 * This project is Demo02
 * Created by cjl on 2021/11/24 12:02 上午.
 */

public abstract class LGCallback<T> implements Callback {

    private final Class<T> clz;

    public LGCallback(Class<T> clz) {
        this.clz = clz;
    }

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onResponse(int status, String msg, String data) {
        BaseResult<T> result = new BaseResult<>();
        result.setStatus(status);
        result.setMsg(msg);
        result.setData(JTools.toObj(data, clz));
        onSuccess(result);
    }

    public abstract void onSuccess(BaseResult<T> result);
}
